package icrts.utils;

import java.lang.Integer;

public class SortedLinkedList <V>{

	SortedLinkedListEntry <V> head;

	public SortedLinkedList(){
		head = null;
	}

	public void insert(double key, V value){

		SortedLinkedListEntry <V> newEntry =
			new SortedLinkedListEntry <V> (key, value);

		SortedLinkedListEntry <V> current = head;

		if ( current == null || current.getKey() >= key ) {
			newEntry.setNext(head);
			head = newEntry;
		}
		else {
			while( current.getNext()!= null && current.getNext().getKey() < key) {
				current = current.getNext();
			} 

			newEntry.setNext(current.getNext());
			current.setNext(newEntry);
		}

	}

	SortedLinkedListEntry <V> getHead(){
		return head;
	}

	public void removeHead(){
		if (head != null)
				head = head.getNext();
	}

	public void printList(){
		SortedLinkedListEntry <V> current = head;

		while (current != null){
			System.out.print("(" + current.getKey() + "," + current.getValue() + ") --> ");
			current = current.getNext();
		}

		System.out.println("null ");

	}

		
}
